import Vue from 'vue'
import VueRouter from 'vue-router'
import modules from '../store/module'
import store from "../store";
import {hasRoute} from '../../lib/utils'
Vue.use(VueRouter)

var router = new VueRouter({
  routes:[
    ...modules,
  ]
})



//
// router.beforeEach((to, form, next) => {
//   if(to.path ==="/login"){
//     return next("/")
//   }else{
//     console.log("to::",to)
//     console.log("!hasRoute(to)::",!hasRoute(to))
//     if(!hasRoute(to)){//判断是否存在当前页面如果不存在就获取路由
//       store.dispatch('DYNAMICROUTERS',{}).then(res=>{
//         if(res.success) {
//           res.data.component.forEach(oMenu => {
//             const{path,component,name} = oMenu;
//             console.log("oMenu::",oMenu)
//             const oRouter = {
//               path:path,
//               component: (resolve) => require([`@/${component}.vue`],resolve) ,
//               name:name
//             }
//             router.addRoute(oRouter)
//           })
//           //最后添加
//          router.addRoute({path:"*",name:'404',component: (resolve) => require([`@/views/404.vue`],resolve)})
//           console.log("router::",router)
//           next({...to,replace:true})
//         }
//       })
//     }else{
//       next()
//     }
//
//   }
// })

export default router
